package servlet;

import java.io.PrintStream;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(name="firstServlet",urlPatterns={"/firstServlet"})
public class FirstServlet extends HttpServlet {


	
	public void service(HttpServletRequest request,HttpServletResponse response)
	throws ServletException,java.io.IOException{

		//设置解码方式
		request.setCharacterEncoding("UTF-8");
		
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charSet=UTF-8");
		
		//下边依次获得表单域的值
		String name=request.getParameter("name");
	    String gender=request.getParameter("gender");
	    //如果请求参数为多个值，将使用该方法获得
	    String[] color=request.getParameterValues("color");
	    String national=request.getParameter("country");
	    
	    //获取页面输出流
	    PrintStream out=new PrintStream(response.getOutputStream(),true,"UTF-8");
	    
	    
	    
	    //输出HTMl页面标签
	    out.println("<html>");
	    out.println("<head>");
	    out.println("<title>servlet 测试</title>");
	    out.println("<head>");
	    out.println("<body>");
	    
	    out.println("您的名字："+name+"<hr/>");

	    out.println("您的性别："+gender+"<hr/>");

	    out.println("您喜欢的颜色：");
	    for(String c:color){
	    	out.println(c+"");
	    }
	    out.println("<hr/>");

	    out.println("您来自的国家："+national+"<hr/>");
	    
	    
	    out.println("<body>");
	    out.println("<html>");
	    
		
	}


	
	

}
